﻿using System;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace Illusion.Component
{
	// Token: 0x020002FD RID: 765
	public class DontDestroyParent : MonoBehaviour
	{
		// Token: 0x06001395 RID: 5013 RVA: 0x0008BB94 File Offset: 0x00089D94
		public static void Register(GameObject obj)
		{
			obj.transform.parent = DontDestroyParent.Instance.transform;
		}

		// Token: 0x06001396 RID: 5014 RVA: 0x0008BBAC File Offset: 0x00089DAC
		public static void Register(MonoBehaviour component)
		{
			DontDestroyParent.Register(component.gameObject);
		}

		// Token: 0x170001D5 RID: 469
		// (get) Token: 0x06001397 RID: 5015 RVA: 0x0008BBBC File Offset: 0x00089DBC
		public static DontDestroyParent Instance
		{
			get
			{
				if (DontDestroyParent.instance == null)
				{
					DontDestroyParent.instance = UnityEngine.Object.FindObjectOfType<DontDestroyParent>();
					if (DontDestroyParent.instance == null)
					{
						GameObject gameObject = new GameObject("DontDestroyParent");
						DontDestroyParent.instance = gameObject.AddComponent<DontDestroyParent>();
					}
					DontDestroyParent.instance.gameObject.hideFlags = HideFlags.NotEditable;
				}
				return DontDestroyParent.instance;
			}
		}

		// Token: 0x06001398 RID: 5016 RVA: 0x0008BC20 File Offset: 0x00089E20
		private void Awake()
		{
			SceneManager.sceneLoaded += delegate(UnityEngine.SceneManagement.Scene scene, LoadSceneMode mode)
			{
				this.Check();
			};
			this.CheckInstance();
		}

		// Token: 0x06001399 RID: 5017 RVA: 0x0008BC3C File Offset: 0x00089E3C
		private void CheckInstance()
		{
			if (DontDestroyParent.Instance == this)
			{
				UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
			}
			else
			{
				UnityEngine.Object.Destroy(base.gameObject);
			}
		}

		// Token: 0x0600139A RID: 5018 RVA: 0x0008BC6C File Offset: 0x00089E6C
		private void Check()
		{
			UnityEngine.Object.Destroy(base.gameObject);
			DontDestroyParent.instance = null;
		}

		// Token: 0x04001897 RID: 6295
		private static DontDestroyParent instance;
	}
}
